package com.hgk.appllication;

import android.content.Context;

import com.baidu.mapapi.SDKInitializer;
import com.common.dongqiuhui.apps.comm.service.BaseBallApplication;
import com.common.dongqiuhui.apps.comm.tools.BallLog;
import com.common.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.common.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.common.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.common.nostra13.universalimageloader.core.DisplayImageOptions;
import com.common.nostra13.universalimageloader.core.ImageLoader;
import com.common.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.common.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.common.nostra13.universalimageloader.core.decode.BaseImageDecoder;
import com.common.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.common.nostra13.universalimageloader.utils.StorageUtils;

import java.io.File;

/**
 * Created by lenovo on 2016/9/22.
 */
public class MyApplication extends BaseBallApplication {
    public static Context applicationContext;
    private static MyApplication instance;
    @Override
    public void onCreate() {
        super.onCreate();
        applicationContext = this;
        instance = this;
        BallLog.enableLog(true);//判断是否打印Log:false-->不打印  true-->打印
        SDKInitializer.initialize(getApplicationContext());
        initImageLoader(getApplicationContext());
    }
    public static MyApplication getInstance(){
        return  instance;
    }
    private void initImageLoader(Context context) {
        //TODO 初始化界面中的图片下载操作
        File cacheDir = StorageUtils.getCacheDirectory(context);
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
                .threadPoolSize(5)
                .threadPriority(Thread.NORM_PRIORITY - 2)
                .tasksProcessingOrder(QueueProcessingType.FIFO)
                .memoryCache(new LruMemoryCache(4 * 1024 * 1024))
                .memoryCacheSizePercentage(10)
                .memoryCacheExtraOptions(480,800)
                .discCacheExtraOptions(480,800,null)
                .discCache(new UnlimitedDiskCache(cacheDir))
                .discCacheFileNameGenerator(new Md5FileNameGenerator())
                .discCacheSize(64*1024*1024)
                .discCacheFileCount(500)
                .imageDownloader(new BaseImageDownloader(this,5*1000,30*1000))
                .imageDecoder(new BaseImageDecoder(true))
                .defaultDisplayImageOptions(DisplayImageOptions.createSimple())//默认图片
                .build();
        ImageLoader.getInstance().init(config);
        ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(getContext()));//对ImagerLoader进行初始化
    }
}
